package com.tencet.dao.impl;

import com.tencet.dao.PersonalDao;
import com.tencet.entity.Personal;
import com.tencet.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.taglibs.standard.tag.common.sql.DataSourceUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @author: King
 * @date: 2022/7/21 14:32
 * @description:
 */
public class PersonalDaoImpl implements PersonalDao {
    private QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
    @Override
    public Personal findAllOne(String pPhone) {
        try {
            return queryRunner.query("select * from personal_center where p_phone=?",new BeanHandler<Personal>(Personal.class),pPhone);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int insertPersonal(Personal personal1) {
        int update = 0;
        try {
            update = queryRunner.update("insert into personal_center (p_name,id_card,p_phone,password) values (?,?,?,?)",personal1.getP_name(),personal1.getId_card(),personal1.getP_phone(),personal1.getPassword());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return update;
    }

    @Override
    public int update(Personal p) {
        int update1=0;
        try {
             update1 = queryRunner.update("update personal_center set detailed_address=? ", p.getDetailed_address());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return update1;
    }




}